package com.itheima.Test002;

import java.io.*;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

@SuppressWarnings("all")
public class Demo {
    public static void main(String[] args) throws Exception {
        Collection<String> list = new ArrayList<>();
        Collections.addAll(list, "大桥未久", "波多野结衣", "苍井空", "abc", "ABC", "小泽玛利亚");
        Collection<String> list2 = (Collection<String>) Proxy.newProxyInstance(list.getClass().getClassLoader(),
                list.getClass().getInterfaces(), new InvocationHandler() {
                    @Override
                    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                        Object invoke = method.invoke(list, objects);
                        if (method.getName().equals("remove")) {
                            for (int i = list.size() - 1; i >= 0; i--) {
                                method.invoke(list, objects);
                            }
                        }
                        return invoke;
                    }
                });
        list2.remove("abc");
        System.setOut(new PrintStream("Day23codes\\123.txt"));
        System.out.println(list);
        /*BufferedReader br = new BufferedReader(new FileReader("Day23codes\\123.txt"));
        BufferedWriter bw = new BufferedWriter(new FileWriter("Day23codes\\aaa.txt"));
        int i ;
        while ((i=br.read())!=-1){
            bw.write(i);
        }
        bw.close();
        br.close();*/
        FileInputStream fis = new FileInputStream("Day23codes\\123.txt");
        FileOutputStream fos = new FileOutputStream("Day23codes\\aaa.txt");
        FileChannel c1 = fis.getChannel();
        FileChannel c2 = fos.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        int i  ;
        while ((i=c1.read(buffer))!=-1){
            buffer.flip();
            c2.write(buffer);
            buffer.clear();
        }
        c1.close();
        c2.close();
        fis.close();
        fos.close();
    }
}
